package com.yupi.springbootinit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yupi.springbootinit.common.BaseResponse;
import com.yupi.springbootinit.common.ResultUtils;
import com.yupi.springbootinit.model.entity.DeviceInfo;
import com.yupi.springbootinit.service.DeviceInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/device-info")
@RequiredArgsConstructor
public class DeviceInfoController {

    private final DeviceInfoService deviceInfoService;

    @GetMapping("/list")
    public BaseResponse<Page<DeviceInfo>> list(@RequestParam(defaultValue = "1") long pageNum,
                                               @RequestParam(defaultValue = "10") long pageSize) {
        Page<DeviceInfo> page = deviceInfoService.page(new Page<>(pageNum, pageSize));
        return ResultUtils.success(page);
    }

    @PostMapping("/create")
    public BaseResponse<Boolean> create(@RequestBody DeviceInfo device) {
        return ResultUtils.success(deviceInfoService.create(device));
    }

    @PostMapping("/update")
    public BaseResponse<Boolean> update(@RequestBody DeviceInfo device) {
        return ResultUtils.success(deviceInfoService.update(device));
    }

    @PostMapping("/delete/{id}")
    public BaseResponse<Boolean> delete(@PathVariable Integer id) {
        return ResultUtils.success(deviceInfoService.remove(id));
    }
}